package priv.dk.springboot.util;

import static priv.dk.springboot.util.CommonUtil.BIZ_ERROR;
import static priv.dk.springboot.util.CommonUtil.BIZ_OK;

public class RespBean<T> {
    private int code;
    private T data;
    private String msg;

    private RespBean() {
    }

    public int getCode() {
        return code;
    }

    public T getData() {
        return data;
    }

    public String getMsg() {
        return msg;
    }

    private RespBean(int code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public static <T> RespBean<T> ok(T data, String msg) {
        return RespBean.ok(BIZ_OK, data, msg);
    }

    public static <T> RespBean<T> ok(T data) {
        return RespBean.ok(data, "ok");
    }

    public static <T> RespBean<T> ok(String msg) {
        return RespBean.ok(null, msg);
    }

    public static <T> RespBean<T> ok() {
        return RespBean.ok("ok");
    }

    public static <T> RespBean<T> ok(int code, T data, String msg) {
        return new RespBean<>(code, data, msg);
    }

    public static <T> RespBean<T> error(int code, T data, String msg) {
        return new RespBean<>(code, data, msg);
    }

    public static <T> RespBean<T> error(T data, String msg) {
        return RespBean.error(BIZ_ERROR, data, msg);
    }

    public static <T> RespBean<T> error(int code, String msg) {
        return RespBean.error(code, null, msg);
    }

    public static <T> RespBean<T> error(String msg) {
        return RespBean.error(null, msg);
    }

    public static <T> RespBean<T> error(T data) {
        return RespBean.error(data, "error");
    }

    public static <T> RespBean<T> error() {
        return RespBean.error("error");
    }

}
